 import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
 import actions from './action';
 import mutations from './mutation';
 import getters from './getter'

 const types = {
   SET_LOCATION: 'SET_LOCATION',
   SET_ADDRESS: 'SET_ADDRESS'
 };
const store =new Vuex.Store({
  state: {
    login:false,
    location: {},
    address: '',
    search:true,
    user_id:'',
    wantlist:[],
  },
  getters: {
    location: state => state.location,
    address: state => state.address
  },
  mutations: {
      login(s, d) {
      s.login= d;
      window.localStorage.setItem("list",JSON.stringify(s.login))
    },
    [types.SET_LOCATION](state, location) {
      if (location) {
        state.location = location;
      } else {
        state.location = null;
      }
    },
    [types.SET_ADDRESS](state, address) {
      if (address) {
        state.address = address;
      } else {
        state.address = '';
      }
    }
  },
  actions: {
    setLocation: ({ commit }, location) => {
      commit(types.SET_LOCATION, location);
    },
    setAddress: ({ commit }, address) => {
      commit(types.SET_ADDRESS, address);
    }
  },
  modules: {
    mutations,
    getters,
    types,
    actions
  },
})
export default store


// WEBPACK FOOTER //
// ./src/store/index.js
//  state:{
//    login:false,
//      username:''
//  }
